<template>
    <nut-cascader :title="title" v-model:visible="visible" @change="onChange" lazy :lazy-load="lazyLoad"
        @click-overlay="visible = false" :options="options"></nut-cascader>
</template>
<script lang="ts" setup>
import { computed } from 'vue';

const props = defineProps({
    title: {
        type: String,
        required: false
    },
    lazyLoad: {
        type: Function,
        required: true
    },

});

const visible = defineModel<boolean>('visible');

const options = defineModel<Array<any>>('options');

const title = computed(() => `当前科室:${props.title == undefined ? "" : props.title}`)

const emits = defineEmits(["onChange", "lazyLoad"])

const onChange = ((...args: any) => {
    emits("onChange", ...args)
})



const lazyLoad = async (node: any, resolve: (children: any) => void) => {
    if (node.root) {
        // const list = await props.lazyLoad("0")
        // resolve(list);
        resolve([]);
    } else {
        if (node?.value?.key) {
            const list = await props.lazyLoad(node.value.key)
            resolve(list);
        } else {
            resolve([]);
        }
    }

}


</script>
